package com.wlyy.his.controller.registration;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wlyy.his.bean.register.qo.GuaHaoRegisterRecordQo;
import com.wlyy.his.bean.register.vo.HisRegisterRecordVo;
import com.wlyy.his.common.api.CommonPage;
import com.wlyy.his.common.enums.DeleteFlagEnum;
import com.wlyy.his.service.ums.IHisRegisterRecordService;
import com.wlyy.his.entity.registration.HisRegisterRecord;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlyy.his.common.api.CommonResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @author
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/register/record")
public class HisRegisterRecordController {
    @Resource
    public IHisRegisterRecordService hisRegisterRecordService;


    /**
     * 查询当前登陆人账号的预约记录
     * @return 结果
     */
    @GetMapping("find")
    public CommonResult<CommonPage<HisRegisterRecordVo>> find(@RequestBody GuaHaoRegisterRecordQo recordQo) {
        Page<HisRegisterRecord> recordPage = hisRegisterRecordService.page(new Page<>(recordQo.getPageNum(), recordQo.getPageSize()), Wrappers.lambdaQuery(HisRegisterRecord.class)
                .eq(HisRegisterRecord::getCreateUser, "123")
                // TODO: 2021/9/6 替换当前登录人
                .eq(HisRegisterRecord::getDeleteFlag, DeleteFlagEnum.NORMAL)
                .orderByDesc(HisRegisterRecord::getCreateTime));
        //转换结果 不返回原生的实体对象
        List<HisRegisterRecordVo> recordVos = recordPage.getRecords().stream().map(re -> BeanUtil.toBean(re, HisRegisterRecordVo.class)).collect(Collectors.toList());
        return CommonResult.success(new CommonPage<>(recordQo, recordPage.getTotal(), recordVos));
    }
}

